package ie.dcu.spca.data.memory;

import java.lang.reflect.UndeclaredThrowableException;
import java.util.LinkedList;
import java.util.List;

import ie.dcu.spca.data.PriceUnitDataManager;
import ie.dcu.spca.model.Bean;
import ie.dcu.spca.model.bean.PriceUnit;

public class MemoryPriceUnitDataManager extends MemoryBasicDataManager
        implements PriceUnitDataManager {

    private static List<PriceUnit> unitList = new LinkedList<PriceUnit>();

    public MemoryPriceUnitDataManager() {
        super();
        unitList.clear();
        resetId();
        unitList.add(newUnit("Item"));
        unitList.add(newUnit("kg"));
    }

    private PriceUnit newUnit(String name) {
        PriceUnit unit = new PriceUnit(getId(), name);
        return unit;
    }

    @Override
    public List<Bean> getBeanList() {
        return (List) unitList;
    }

    @Override
    public void delete(int id) {
        throw new UndeclaredThrowableException(null);
    }

    @Override
    public int getId(Bean bean) {
        return ((PriceUnit) bean).getId();
    }

    @Override
    public String getName(Bean bean) {
        return (String) ((PriceUnit) bean).getName();
    }

    @Override
    public int getLastId() {
        return unitList.get(unitList.size() - 1).getId();
    }

    @Override
    public PriceUnit get(int id) {
        return unitList.get(getPositionByBeanId(id));
    }

    @Override
    public int getFirstId() {
        return unitList.get(0).getId();
    }

}
